﻿using System;
using System.Threading.Tasks;
using GroupsExample;
using Microsoft.AspNet.SignalR;
using Microsoft.Owin;
using Microsoft.Owin.Cors;
using Owin;

[assembly: OwinStartup(typeof(GuideAPI.Startup))]

namespace GuideAPI
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            var hubConfiguration = new HubConfiguration();
            //enable detailed error messages
            hubConfiguration.EnableDetailedErrors = true;
            //disable automatically generated javascript proxy files
            hubConfiguration.EnableJavaScriptProxies = false;

            //any connection or hub wire up and configuration should go here
            GlobalHost.HubPipeline.AddModule(new ErrorHandlingPipelineModule());
            GlobalHost.HubPipeline.AddModule(new LoggingPipelineModule());

            //app.MapSignalR("/signalr", hubConfiguration);
            //implement cross-domain requests 
            app.Map("/signalr", map =>
            {
                map.UseCors(CorsOptions.AllowAll);
                var hubConfiguration2 = new HubConfiguration();
                map.RunSignalR(hubConfiguration2);
                GlobalHost.HubPipeline.AddModule(new ChatHub.RejoingGroupPipelineModule());
                //require authentication for all hubs
                GlobalHost.HubPipeline.RequireAuthentication();
            });
        }
    }
}
